#include "MyDialogUI.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFrame>

MyDialogUI::MyDialogUI(QWidget *parent)
        : QWidget(parent)
{
    setWindowFlags(Qt::FramelessWindowHint);
    // 左侧区域（label2）
    label2 = new QTextEdit("左侧内容");
    label2->setAlignment(Qt::AlignCenter);
    label2->setStyleSheet("background-color: lightblue;");

    QScrollArea *scrollLeft = new QScrollArea;
    scrollLeft->setWidget(label2);
    scrollLeft->setWidgetResizable(true);

    // 中间按钮区域
    QWidget *centerWidget = new QWidget;
    QVBoxLayout *centerLayout = new QVBoxLayout(centerWidget);
    centerLayout->setContentsMargins(10, 10, 10, 10);
    centerLayout->setSpacing(15);

    btn = new QPushButton("按钮");
    btnInputImag1 = new QPushButton("图1识别");
    btnInputImag2 = new QPushButton("图2识别");

    InputTextLabel = new QLabel("提示词");
    InputTextLabel->setStyleSheet("background-color: lightgray; font-size: 14px; min-width: 120px; height: 35px;");
    InputTextLabel->setAlignment(Qt::AlignCenter);

    InputTextEdit = new QTextEdit("请输入提示词");
    InputTextEdit->setStyleSheet("background-color: lightgray; font-size: 14px; min-width: 120px; height: 80px;");
    InputTextEdit->setMinimumHeight(50);
    InputTextEdit->setAlignment(Qt::AlignCenter);

    btnCompare = new QPushButton("对比");

    // 统一按钮样式
    QString btnStyle = "background-color: lightgray; font-size: 14px; min-width: 120px; height: 35px;";
    btn->setStyleSheet(btnStyle);
    btnInputImag1->setStyleSheet(btnStyle);
    btnInputImag2->setStyleSheet(btnStyle);
    btnCompare->setStyleSheet(btnStyle);

    centerLayout->addWidget(btn, 0, Qt::AlignHCenter);
    centerLayout->addWidget(btnInputImag1, 0, Qt::AlignHCenter);
    centerLayout->addWidget(btnInputImag2, 0, Qt::AlignHCenter);
    centerLayout->addWidget(InputTextLabel, 0, Qt::AlignHCenter);
    centerLayout->addWidget(InputTextEdit, 0, Qt::AlignHCenter);
    centerLayout->addWidget(btnCompare, 0, Qt::AlignHCenter);
    centerLayout->addStretch();

    QScrollArea *scrollCenter = new QScrollArea;
    scrollCenter->setWidget(centerWidget);
    scrollCenter->setWidgetResizable(true);
    scrollCenter->setMinimumWidth(160);

    // 右侧区域（label3）
    label3 = new QTextEdit("右侧内容");
    label3->setAlignment(Qt::AlignCenter);
    label3->setStyleSheet("background-color: lightgreen;");

    QScrollArea *scrollRight = new QScrollArea;
    scrollRight->setWidget(label3);
    scrollRight->setWidgetResizable(true);

    // 使用 QSplitter
    QSplitter *splitter = new QSplitter(Qt::Horizontal);
    splitter->addWidget(scrollLeft);
    splitter->addWidget(scrollCenter);
    splitter->addWidget(scrollRight);

    // 设置比例（40% : 40% : 20%）
    splitter->setStretchFactor(0, 4);
    splitter->setStretchFactor(1, 2);
    splitter->setStretchFactor(2, 4);

    // 最外层布局
    QHBoxLayout *mainLayout = new QHBoxLayout(this);
    mainLayout->addWidget(splitter);
    setLayout(mainLayout);

    setWindowTitle("MyDialogUI - QSplitter + QScrollArea");
    resize(800, 500);
}
